Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

255
Visualizações
Cant update ApexChart graph with JavaScript...>

Im trying to refresh a chart after fetching data from MySQL but my updateChart function isnt being executed.

I know it's not being executed because the console.logs (displaying the Boo! and displaying the driversChartData array are not being displayed in the console. I know there is data in the array because it consoles out the data if I do the console.log from outside the function.

Any idea why my function isnt being run after the if statement?

(Ive tried removing the whole if statement in case it interfered but to no avail). Must be a really single thing, but Im new to JS so any help would be greatly appreciated :)

Thanks. M.

document.addEventListener('DOMContentLoaded', function () {
    fetch('http://127.0.0.1:3000/driversChart')
    .then(response => response.json())
    .then(data => loadDriversChart(data['data']));
});

function loadDriversChart(driversChartData) {

    const driversChartArea = document.querySelector("#driversChart");

    if (driversChartData.length === 0) {
        var options = {
            chart: {
                height: 350,
                type: 'line',
            },
            dataLabels: {
                enabled: false
            },
            series: [],
            title: {
                text: 'F1 Drivers Points Repartition',
            },
            noData: {
              text: 'Loading Drivers Chart...'
            }
          }
          
          var chart = new ApexCharts(
            document.querySelector("#driversChart"),
            options
          );
          
          chart.render();
    }

    // Data is fetched so update the Drivers' Chart
    function updateChart(driversChartData) {
        console.log('Boo!');
        console.log(driversChartData);
        driversChartArea.updateSeries( [ {
          name: 'F1 Drivers Points Repartition',
          data: driversChartData
        } ] );
      };
}
about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda